import logging
from config import BASE_HOST


class RechargeApi:

    def __init__(self, session):
        # 接收session对象的变量
        self.session = session

    # 获取充值验证码接口
    def get_recharge_verify_code(self, r):
        url = (BASE_HOST + f'/common/public/verifycode/{r}')
        resp = self.session.get(url)
        logging.info(f'获取充值验证码接口返回的响应码{resp.status_code}')
        return resp

    # 充值接口
    def recharge(self, amount_v, valicode, paymentType='chinapnrTrust', formStr='reForm'):
        # 定义一个字典变量，用来接收请求体数据
        url = (BASE_HOST + '/trust/trust/recharge')
        data = {'paymentType': paymentType, 'amount': amount_v, 'formStr': formStr, 'valicode': valicode}
        resp = self.session.get(url, data=data)
        return resp

    # 第三方充值接口

    def third_recharge(self, url, form_dict):
        response = self.session.post(url=url, data=form_dict)
        logging.info(f'开户接口{response.text}')
        # 封装方法的返回
        return response
